export function formatTime(times) {
	const date = new Date(times);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');
	return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export function nowFormatTime(times) {
	const date = new Date(times);
	const now = new Date();
	const diffTime = Math.abs(now - date);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	const seconds = String(date.getSeconds()).padStart(2, '0');
	if (diffTime < 24 * 60 * 60 * 1000) {
		return `${hours}:${minutes}`;
	} else if (diffTime < 7 * 24 * 60 * 60 * 1000) {
		const weekDay = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
		const week = weekDay[date.getDay()];
		return `${week} ${hours}:${minutes}`;
	} else {
		if (now.getFullYear() === year) {
			return `${month}-${day} ${hours}:${minutes}`;
		} else {
			return `${year}-${month}-${day} ${hours}:${minutes}`;
		}
	}
}

export function yearMonthTime(times) {
	const date = new Date(times);
	const now = new Date();
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	const hours = String(date.getHours()).padStart(2, '0');
	const minutes = String(date.getMinutes()).padStart(2, '0');
	if (now.getFullYear() === year && now.getMonth() === date.getMonth() && now.getDate() === date.getDate()) {
		// 当天
		return `${hours}:${minutes}`;
	} else if (now.getFullYear() === year) {
		return `${month}-${day}`;
	} else {
		// 去年或更早
		return `${year}-${month}-${day}`;
	}
}

export function yearmondayTime(times) {
	const date = new Date(times);
	const year = date.getFullYear();
	const month = String(date.getMonth() + 1).padStart(2, '0');
	const day = String(date.getDate()).padStart(2, '0');
	return `${year}-${month}-${day}`;
}